# -*- coding: utf-8 -*-
#----------------------------------------------------------------------------#
# strokeTable.py
# Zhihui Jin <zhihuijin@gmail.com>
# vim: ts=4 sw=4 sts=4 et tw=78:
# Wed Jul 25 16:16:02 JST 2007
#
#----------------------------------------------------------------------------#

""" A table for stroke of hanChar
"""

#----------------------------------------------------------------------------#

import os
from www import settings
from tools.common import sopen

#----------------------------------------------------------------------------#
# PUBLIC
#----------------------------------------------------------------------------#


_structureDir = os.path.join(settings.DATA_DIR, 'structure')
_strokeTable =  os.path.join(_structureDir, 'cjk_stroke_utf8')

#----------------------------------------------------------------------------#

#----------------------------------------------------------------------------#

class StrokeTable(dict):
    """ A dict which strore stoke order for hanchar
    """
    #------------------------------------------------------------------------#
    # PUBLIC METHODS
    #------------------------------------------------------------------------#

    def __init__(self):
        """ Constructor.
        """

        # Load the stroke table 
        for line in sopen(_strokeTable):
            char, stroke = line.rstrip().split()
            self[char] = stroke

        return

    #------------------------------------------------------------------------#
    def asciiForm (self, char):
        """ give the ascii form of stroke order
        stroke description :
        东 15234
        1 hrizontal
        2 vertical
        3 left
        4 right
        5 other
        """
        stroke = ''
        for s in self[char]:
            if s == '1' :
                stroke += 'h'
            elif s == '2':
                stroke += 'v'
            elif s == '3':
                stroke += 'l'
            elif s == '4':
                stroke += 'r'
            elif s == '5':
                stroke += 'o'

        return stroke

    #------------------------------------------------------------------------#

#----------------------------------------------------------------------------#

# vim: ts=4 sw=4 sts=4 et tw=78:
